package solution;

public class RemoveElements {

    public static ListNode removeElements(ListNode head, int val) {
        // head 不为 null
        if(head == null) {
            return null;
        }
        // 如果第一个就是
        while(head != null && head.val == val) {
            head = head.next;
        }

        ListNode cur = head;
        ListNode prev = head;

        while(cur != null) {
            // 相同
            if(cur.val == val) {
                prev.next = cur.next;
                cur = cur.next;
                continue;
            }
            prev = cur;
            cur = cur.next;
        }

        return head;
    }
}
